import { reqCategoryList } from "@/api";
import { getBannerList, getFlootList } from "@/api/mock.js";
const state = {
  //分类数据
  categoryList: [],
  //首页轮播图
  bannerList: [],
  //floor的数据
  floorList: [],
};
const mutations = {
  //设置分类数据
  setCategoryList(state, data) {
    state.categoryList = data.slice(0, 16);
  },
  //设置首页轮播图数据
  setBannerList(state, data) {
    state.bannerList = data;
  },
  //设置floor的数据
  setFloorList(state, data) {
    state.floorList = data;
  },
};
const actions = {
  //通过调用接口
  async CategoryList({ commit }) {
    const res = await reqCategoryList();
    if (res.code === 200) {
      commit("setCategoryList", res.data);
    }
  },
  //获取首页轮播图
  async getBannerList({ commit }) {
    const res = await getBannerList();
    if (res.code === 200) {
      commit("setBannerList", res.data);
    }
  },
  //获取floor数据
  async getFlootList({ commit }) {
    const res = await getFlootList();
    if (res.code === 200) {
      //调用mutations
      commit("setFloorList", res.data);
    }
  },
};
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
